package concept.chapter7.sorting;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * A concept proven class demonstrating: 
 * <p>
 * 1. Differences between <code>Comparable</code> and <code>Comparator</code>
 * <p>
 * 2. Similarities between <code>Collections</code> and <code>Arrays</code>
 * 
 * @author kan.sun
 */
public class TestSort1
{
	public static void main(String[] args)
	{
		List<DVDInfo> stuff = new ArrayList<DVDInfo>();

		populateList(stuff);
		
		System.out.println("Unsorted on title: \n"+stuff);
		Collections.sort(stuff);
		System.out.println("Sorted on title: \n"+stuff);
		
		System.out.println("Unsorted on genre: \n"+stuff);
		Collections.sort(stuff, new GenreSort());
		System.out.println("Sorted on genre: \n"+stuff);
		
		DVDInfo[] dvds = stuff.toArray(new DVDInfo[0]);
		
		Arrays.sort(dvds);
		System.out.println("Sorted on title: \n"+dvds);
		for(DVDInfo dvd:dvds)
		{
			System.out.println(dvd);
		}
		
		Arrays.sort(dvds, new GenreSort());
		System.out.println("Sorted on genre: \n"+dvds);
		for(DVDInfo dvd:dvds)
		{
			System.out.println(dvd);
		}
	}
	
	static void populateList(List<DVDInfo> list)
	{
		DVDInfo dvd1 = new DVDInfo("Raiders of the Lost Ark", "action", "Ford, Harrison");
		DVDInfo dvd2 = new DVDInfo("2001", "sci-fi", "??");
		DVDInfo dvd3 = new DVDInfo("Caddy Shack", "comedy", "Murray, Bill");
		DVDInfo dvd4 = new DVDInfo("Star Wars", "sci-fi", "Ford, Harrison");
		DVDInfo dvd5 = new DVDInfo("Lost in translation", "comedy", "Murray, Bill");
		DVDInfo dvd6 = new DVDInfo("Patriot Games", "action", "Ford, Harrison");
		
		list.clear();
		list.add(dvd1);
		list.add(dvd2);
		list.add(dvd3);
		list.add(dvd4);
		list.add(dvd5);
		list.add(dvd6);
	}
}
